package org.icop.utils;

import java.util.HashMap;
import java.util.Map;

import org.jbpt.algo.tree.rpst.IRPST;
import org.jbpt.algo.tree.rpst.RPST;
import org.jbpt.graph.abs.IDirectedEdge;
import org.jbpt.graph.abs.IDirectedGraph;
import org.jbpt.hypergraph.abs.IVertex;

public class RPSTCache {

	private static RPSTCache eInstance = null;
	
	public static RPSTCache getInstance() {
		if (eInstance == null)
			eInstance = new RPSTCache();
		
		return eInstance;
	}
	
	private Map<IDirectedGraph<IDirectedEdge<IVertex>, IVertex>, IRPST<IDirectedEdge<IVertex>, IVertex>> trees = new HashMap<>();

	public IRPST<IDirectedEdge<IVertex>, IVertex> getRPSTForGraph(IDirectedGraph<IDirectedEdge<IVertex>, IVertex> g) {
		if (!this.trees.containsKey(g))
			this.trees.put(g,new RPST<IDirectedEdge<IVertex>, IVertex>(g));
		
		return this.trees.get(g);
	}

}
